﻿var ajaxUrl = '/hx.aspx';

function menuHover(id) {
    $('#topmenu ul').children().removeClass('current');
    $('#pmid-' + id).addClass('current');
    $('#panel').children().css('display',"none");
    $('#mid-' + id).css('display', "");    
}

function showTips() {  
    pnotify();
    var interval = setInterval(function() {
        pnotify();
    }, 2000);
}

function pnotify()
{
    $.pnotify({
        title: '有新订单了！',
        text: '订单TK' + Math.round(Math.random() * 99999999)
    });
}

function dyn_notice() {
    var percent = 0;
    var notice = $.pnotify({
        title: "Please Wait",
        type: 'info',
        icon: 'picon picon-throbber',
        hide: false,
        closer: false,
        sticker: false,
        opacity: .75,
        shadow: false,
        width: "150px"
    });

    setTimeout(function() {
        notice.pnotify({
            title: false
        });
        var interval = setInterval(function() {
            percent += 2;
            var options = {
                text: percent + "% complete."
            };
            if (percent == 80) options.title = "Almost There";
            if (percent >= 100) {
                window.clearInterval(interval);
                options.title = "Done!";
                options.type = "success";
                options.hide = true;
                options.closer = true;
                options.sticker = true;
                options.icon = 'picon picon-task-complete';
                options.opacity = 1;
                options.shadow = true;
                options.width = $.pnotify.defaults.width;
                //options.min_height = "300px";
            }
            notice.pnotify(options);
        }, 120);
    }, 2000);
}

G={};
G.app={};
G.app.mycenter = G.app.mycenter || {};
G.app.mycenter.order = {
	myorderinit: function() {$("table .js_order_status_history").hover(function() {
			var a = $(this),
				b = a.parent();
			clearTimeout(a.data("timer"));
			b.addClass("status_layout_on");
			if (!a.data("requested")) {
				var c = '<table class="table_info" style="width:100%"><colgroup><col class="col1"><col class="col2"><col class="col3"><col class="col4"></colgroup><thead><tr><td>操作人</td><td>操作时间</td><td>操作状态</td><td>操作备注</td></tr></thead><tbody class="js_tbody"><tr><td colspan="4" style="text-align:center;padding:5px">正在请求，请稍侯...</td></tr></tbody><tfoot class="js_tfooter" style="display:none"><tr><td colspan="4"></td></tr></tfoot></table>';
				b.find(".order_box .layout_bd").html(c);
				a.data("requested", true);
				b.find(".layout_popup").unbind("mouseenter").unbind("mouseleave").hover(function() {
					clearTimeout(a.data("timer"));
					b.addClass("status_layout_on")
				}, function() {
					b.removeClass("status_layout_on")
				});
				$.ajax({
					type: "get",
					url: ajaxUrl+"?oper=orderflow&oid=" + a.attr("order_id")+"&rnd="+Math.round(Math.random() * 10),
					timeout: 1000 * 10,
					dataType: "json",
					success: function(g) {		
						var l = "",
							m = "",
							e = null;
						if (g && g.msg == "suc") {
							var j = g.data;
							$.each(j, function(index, item) {
								l += "<tr><td>" + item.oper + "</td><td>" + item.time + "</td><td>" + item.status + "</td><td>" + item.memo + "</td></tr>"
							});
						} else {
							l = '<tr><td colspan="4">' + (g.data || "查询订单流水失败") + "</td></tr>";
						}
						b.find(".order_box .js_tbody").html(l);
					},
					error: function() {
						a.data("requested", false)
					}
				})
			}
		}, function() {
			var a = $(this);
			clearTimeout(a.data("timer"));
			var b = setTimeout(function() {
				a.parent().removeClass("status_layout_on")
			}, 100);
			a.data("timer", b)
		}),
		$("table .js_policy_status_history").hover(function() {
			var a = $(this),
				b = a.parent();
			clearTimeout(a.data("timer"));
			b.addClass("status_layout_on");
			if (!a.data("requested")) {
				var c = '<table class="table_info" style="width:100%"><colgroup><col class="col1"><col class="col2"><col class="col3"><col class="col4"></colgroup><thead><tr><td>操作人</td><td>操作时间</td><td>操作状态</td><td>操作备注</td></tr></thead><tbody class="js_tbody"><tr><td colspan="4" style="text-align:center;padding:5px">正在请求，请稍侯...</td></tr></tbody><tfoot class="js_tfooter" style="display:none"><tr><td colspan="4"></td></tr></tfoot></table>';
				b.find(".order_box .layout_bd").html(c);
				a.data("requested", true);
				b.find(".layout_popup").unbind("mouseenter").unbind("mouseleave").hover(function() {
					clearTimeout(a.data("timer"));
					b.addClass("status_layout_on")
				}, function() {
					b.removeClass("status_layout_on")
				});
				$.ajax({
					type: "get",
					url: ajaxUrl+"?oper=policyflow&pid=" + a.attr("policy_id")+"&rnd="+Math.round(Math.random() * 10),
					timeout: 1000 * 10,
					dataType: "json",
					success: function(g) {		
						var l = "",
							m = "",
							e = null;
						if (g && g.msg == "suc") {
							var j = g.data;
							$.each(j, function(index, item) {
								l += "<tr><td>" + item.oper + "</td><td>" + item.time + "</td><td>" + item.status + "</td><td>" + item.memo + "</td></tr>"
							});
						} else {
							l = '<tr><td colspan="4">' + (g.data || "查询保单流水失败") + "</td></tr>";
						}
						b.find(".order_box .js_tbody").html(l);
					},
					error: function() {
						a.data("requested", false)
					}
				})
			}
		}, function() {
			var a = $(this);
			clearTimeout(a.data("timer"));
			var b = setTimeout(function() {
				a.parent().removeClass("status_layout_on")
			}, 100);
			a.data("timer", b)
		}),
		$("table .js_invoice_status_history").hover(function() {
			var a = $(this),
				b = a.parent();
			clearTimeout(a.data("timer"));
			b.addClass("status_layout_on");
			if (!a.data("requested")) {
				var c = '<table class="table_info" style="width:100%"><colgroup><col class="col1"><col class="col2"><col class="col3"><col class="col4"></colgroup><thead><tr><td>操作人</td><td>操作时间</td><td>操作状态</td><td>操作备注</td></tr></thead><tbody class="js_tbody"><tr><td colspan="4" style="text-align:center;padding:5px">正在请求，请稍侯...</td></tr></tbody><tfoot class="js_tfooter" style="display:none"><tr><td colspan="4"></td></tr></tfoot></table>';
				b.find(".order_box .layout_bd").html(c);
				a.data("requested", true);
				b.find(".layout_popup").unbind("mouseenter").unbind("mouseleave").hover(function() {
					clearTimeout(a.data("timer"));
					b.addClass("status_layout_on")
				}, function() {
					b.removeClass("status_layout_on")
				});
				$.ajax({
					type: "get",
					url: ajaxUrl+"?oper=GetInvoiceOrderFlowList&orderFid=" + a.attr("invoice_id")+"&rnd="+Math.round(Math.random() * 10),
					timeout: 1000 * 10,
					dataType: "json",
					success: function(g) {		
						var l = "",
							m = "",
							e = null;
						if (g && g.msg == "suc") {
							var j = g.data;
							$.each(j, function(index, item) {
								l += "<tr><td>" + item.oper + "</td><td>" + item.time + "</td><td>" + item.status + "</td><td>" + item.memo + "</td></tr>"
							});
						} else {
							l = '<tr><td colspan="4">' + (g.data || "查询发票订单流水失败") + "</td></tr>";
						}
						b.find(".order_box .js_tbody").html(l);
					},
					error: function() {
						a.data("requested", false)
					}
				})
			}
		}, function() {
			var a = $(this);
			clearTimeout(a.data("timer"));
			var b = setTimeout(function() {
				a.parent().removeClass("status_layout_on")
			}, 100);
			a.data("timer", b)
		}),
		$("table .js_order_address").hover(function() {
          var a = $(this),
				b = a.parent();
			clearTimeout(a.data("timer"));
			b.addClass("status_layout_on");
			if (!a.data("requested")) {
				var c = '<table class="table_info" style="width:100%"><colgroup><col class="col1"><col class="col2"><col class="col3"><col class="col4"></colgroup><thead><tr><td>省份</td><td>城市</td><td style=\"width:30%\">地址</td><td>联系人</td><td>联系电话</td></tr></thead><tbody class="js_tbody"><tr><td colspan="4" style="text-align:center;padding:5px">正在请求，请稍侯...</td></tr></tbody><tfoot class="js_tfooter" style="display:none"><tr><td colspan="4"></td></tr></tfoot></table>';
				b.find(".order_box .layout_bd").html(c);
				a.data("requested", true);
				b.find(".layout_popup").unbind("mouseenter").unbind("mouseleave").hover(function() {
					clearTimeout(a.data("timer"));
					b.addClass("status_layout_on")
				}, function() {
					b.removeClass("status_layout_on")
				});
				$.ajax({
					type: "get",
					  url: ajaxUrl + "?oper=GetOrderAddress&oid=" + a.attr("order_id")+"&rnd="+Math.round(Math.random() * 10),
					timeout: 1000 * 10,
					dataType: "json",
					success: function(g) {		
						var l = "",
							m = "",
							e = null;
						if (g && g.msg == "suc") {
							var j = g.data;
							$.each(j, function(index, item) {
								l += "<tr><td>" + item.province + "</td><td>" + item.city + "</td><td>" + item.address + "</td><td>" + item.contact + "</td><td>" + item.tel + "</td></tr>"
							});
						} else {
							l = '<tr><td colspan="4">' + (g.data || "查询配送地址失败") + "</td></tr>";
						}
						b.find(".order_box .js_tbody").html(l);
					},
					error: function() {
						a.data("requested", false)
					}
				})
			}
        }, function() {
            var a = $(this);
            clearTimeout(a.data("timer"));
            var b = setTimeout(function() {
                a.parent().removeClass("status_layout_on")
            }, 100);
            a.data("timer", b)
        }),
		$("table .js_invoice_uncheck").click(function() {
			var a = $(this),
				b = a.parent();
			b.addClass("status_layout_on");
			if (!a.data("requested")) {
				var c = $('<div"><div><h3><span>&gt;审核不通过原因</span></h3>原因<input type="text" id="reason_'+a.attr("invoice_id")+'"/><input type="button" value="提交" onclick="NoCheckInvoiceOrder(\''+a.attr("invoice_id")+'\')"/><input type="button" class="close" value="关闭" onclick=""/></div>');
				b.find(".order_box .layout_bd").html(c);
				a.data("requested", true);
				b.find(".layout_popup").unbind("click").click(function() {
					b.addClass("status_layout_on")
				}, function() {
					//b.removeClass("status_layout_on")
				});
				b.find(".close").click(function() {
					b.removeClass("status_layout_on")
  		        });
			}
		}),$("table .js_invoice_deliversuc").click(function() {
			var a = $(this),
				b = a.parent();
			b.addClass("status_layout_on");
			if (!a.data("requested")) {
				var c = $('<div"><div><h3><span>&gt;配送</span></h3>快递公司<input type="text" id="comp_'+a.attr("invoice_id")+'"/>快递单号<input type="text" id="fedex_'+a.attr("invoice_id")+'"/><br/><input type="button" value="提交" onclick="DeliverInvoiceOrder(\''+a.attr("invoice_id")+'\')"/><input type="button" class="close" value="关闭" onclick=""/></div>');
				b.find(".order_box .layout_bd").html(c);
				a.data("requested", true);
				b.find(".layout_popup").unbind("click").click(function() {
					b.addClass("status_layout_on")
				}, function() {
					//b.removeClass("status_layout_on")
				});
				b.find(".close").click(function() {
					b.removeClass("status_layout_on")
  		        });
			}
		})
	}
};

function userLogin(isc) {
    var isc = isc;
    $('#divName').css('display', 'none');
    $('#divPwd').css('display', 'none');
    $('#divCode').css('display', 'none');
    $('#divLoginMsg').css('display', 'none');
    showMessage('#divLoginMsg', '正在登录,请稍候...', true);
    var unCtrl = $('#txtUserName');
    var pwdCtrl = $('#txtPassword');
    var codeCtrl = $('#txtIdentityCode');
    var autoCtrl = $('#txtAutoLogin');
    var userName = $.trim(unCtrl.val());
    var pwd = $.trim(pwdCtrl.val());
    var code = $.trim(codeCtrl.val());
    var auto = 1;
    if (autoCtrl != null && isc == '1') {
        auto = $.trim(autoCtrl.val());
    }
    if (userName == '') {
        showMessage('#divName', '请输入用户名。');
        $('#divLoginMsg').css('display', 'none');
        //unCtrl.focus();
        return;
    }
    if (pwd == '') {
        showMessage('#divPwd', '请输入密码。');
        $('#divLoginMsg').css('display', 'none');
        //pwdCtrl.focus();
        return;
    }
    if (code == '') {
        showMessage('#divCode', '请输入验证码。');
        $('#divLoginMsg').css('display', 'none');
        //codeCtrl.focus();
        return;
    }
    var url = ajaxUrl;
    $.ajax({
        type: 'POST',
        url: url,
        data: { oper: 'userLogin', pwd: pwd, username: userName, identitycode: code, auto: auto },
        success: function(request) {
            $('#divLoginMsg').css('display', 'none');
            var flag = request;
            if (request.responseText == 'invalidOrNull') {
                showMessage('#divLoginMsg', '系统错误。');
                return;
            }
            $('#divLoginMsg').css('display', 'none');
            if (flag == '1') {
                if (document.referrer) { document.location = document.referrer; }
                else { document.location = '/Default.aspx'; }
            }
            else {
                changeCode();
                $('#divLoginMsg').css('display', 'none');
                if (flag == '-1') {
                    showMessage('#divName', '用户名或密码错误。');
                    unCtrl.focus();
                    return;
                }
                if (flag == '-2') {
                    showMessage('#divCode', '验证码错误。');
                    codeCtrl.focus();
                    return;
                }
                //              if (flag.length <= 20)
                //              { showMessage('#divLoginMsg', flag); }
                //              else
                //              { showMessage('#divLoginMsg', '系统错误，请稍候再登录。'); }
                //              unCtrl.focus();
            }
        },
        dataType: 'json'
    });
}

function showMessage(divName, message, messageType) {
    var divCtrl = $(divName);
    if (divCtrl != null) {
        if (messageType)
        { divCtrl.addClass('Send_Ok'); } else { divCtrl.addClass('error'); }
        divCtrl.css('display', 'block');
        divCtrl.html(message);
    }
}

function changeCode() {
    var img = $('#imgCode');
    var ran = Math.random() * 1000;
    img.attr('src', '/VerifyImagePage.aspx?randomcode=' + ran);
}

function textChange(txtCtrl, msgCtrlName, length, msg) {
    $(msgCtrlName).css('display', 'none');
    var value = $.trim(txtCtrl.value);
    if (value.length < length) {
        showMessage(msgCtrlName, msg);
    }
}


function SetProgree(visible) {
    if (visible) {
        $(".DivProgressInfo").show();
    }
    else {
        $(".DivProgressInfo").hide();
    }
}

//按钮变灰
function ButtonEnabled(buttonID, enabled) {
    if (enabled) {
        $("#" + buttonID).css("filter", "");
        $("#" + buttonID).css("-moz-opacity", "");
        $("#" + buttonID).css("-moz-opacity", "");
        //$("#" + buttonID).css("color", "#1885c4");
        $("#" + buttonID).attr("disabled", "");
    }
    else {
        $("#" + buttonID).css("filter", "alpha(opacity=70)");
        $("#" + buttonID).css("-moz-opacity", "0.7");
        $("#" + buttonID).css("-moz-opacity", "0.7");
        $("#" + buttonID).css("color", "");
        $("#" + buttonID).attr("disabled", "disabled");
    }
}

function loading() {
    $("#loading_img").css('display', 'block');
    $('#loading_img').html('<img src="/img/loading.gif"/>');
}
function unloading() {
    $("#loading_img").css('display', 'none');
    $('#loading_img').html();
}

function GetDiffDetail(name, st, et) {
    loading();
    $.getJSON(ajaxUrl, { oper: "GetDiffDetail", un: name, et: et, st: st }, function(data) {
        if (data && data.msg == "suc") {
            aa = "<h3>" + name + "</h3>";
            aa = aa + "<table><thead><tr><th>商品编号</th><th>商品名称</th><th>商品总额</th><th>实付总额</th><th>差价</th><th>议价金额</th></tr></thead><tbody>";
            for (var i = 0; i < data.diffs.length; i++) {
                aa = aa + "<tr><td>" + data.diffs[i].goodsid + "</td><td>" + data.diffs[i].goodsname + "</td><td>" + data.diffs[i].price + "</td><td>" + data.diffs[i].realprice + "</td>";
                if (data.diffs[i].diff == "0.00")
                    aa = aa + "<td>" + data.diffs[i].diff + "</td>";
                else
                    aa = aa + "<td style=\"color:red;\">" + data.diffs[i].diff + "</td>";
                if (data.diffs[i].bargain == "0.00")
                    aa = aa + "<td>" + data.diffs[i].bargain + "</td></tr>";
                else
                    aa = aa + "<td style=\"color:red;\">" + data.diffs[i].bargain + "</td></tr>";
            }
            aa = aa + "</tbody></table>";
            unloading();
            $("#loading_img").html(aa);
            $("#loading_img").css('display', 'block');
        }
        else unloading();
    });
}
function GetSales(custFid,start,end) {
//    var start = $("#fromDate").val();
//    var end = $("#toDate").val();
    loading();
    $.getJSON(ajaxUrl, { oper: "GetSales", start: start, end: end, custFid: custFid }, function(g) {
        if (g && g.msg == "suc") {
            var content = "<table><thead><tr><th width=\"18%\">订单号</th><th width=\"40%\">产品名称</th><th width=\"15%\">保单号</th><th width=\"10%\">保单金额</th><th width=\"18%\">订单时间</th></tr></thead><tbody>";
            var j = g.data;
            $.each(j, function(index, item) {
            content += "<tr><td>" + item.orderNo + "</td><td>" + item.product + "</td><td>" + item.policyNo + "</td><td>" + item.price + "</td><td>" + item.orderTime + "</td></tr>";
            });
            content = content + "</tbody></table>";            
            unloading();
            $("#loading_img").html(content);
            $("#loading_img").css('display', 'block');
        }
        else unloading();
    });
}
function GetSalesDetail(user, start, end,product) {
    //    var start = $("#fromDate").val();
    //    var end = $("#toDate").val();
    loading();
    $.getJSON(ajaxUrl, { oper: "GetSalesDetail", start: start, end: end, user: user,product:product }, function(g) {
        if (g && g.msg == "suc") {
            var content = "<table><thead><tr><th width=\"18%\">订单号</th><th width=\"35%\">产品名称</th><th width=\"20%\">保单号</th><th width=\"10%\">保单金额</th><th width=\"18%\">订单时间</th></tr></thead><tbody>";
            var j = g.data;
            $.each(j, function(index, item) {
                content += "<tr><td>" + item.orderNo + "</td><td>" + item.product + "</td><td>" + item.policyNo + "</td><td>" + item.price + "</td><td>" + item.orderTime + "</td></tr>";
            });
            content = content + "</tbody></table>";
            unloading();
            $("#loading_img").html(content);
            $("#loading_img").css('display', 'block');
        }
        else unloading();
    });
}
function GetFlowDetail(type, typeid, st, et) {
    loading();
    $.getJSON(ajaxUrl, { oper: "GetFlowDetail", un: typeid, et: et, st: st }, function(data) {
        if (data && data.msg == "suc") {
            aa = "<h3>" + type + "</h3>";
            aa = aa + "<table><thead><tr><th>时间</th><th>交易金额</th><th>交易号</th><th>备注</th></tr></thead><tbody>";
            for (var i = 0; i < data.flows.length; i++) {
                aa = aa + "<tr><td style='text-align:center;'>" + data.flows[i].flowtime + "</td><td>" + data.flows[i].flowchange + "</td><td style='text-align:center;'>" + data.flows[i].flowpayid + "</td><td style='text-align:left;'>" + data.flows[i].flowmemo + "</td></tr>";
            }
            aa = aa + "</tbody></table>";
            unloading();
            $("#loading_img").html(aa);
            $("#loading_img").css('display', 'block');
        }
        else unloading();
    });
}

function GetOnlineUsers(name) {
    $.getJSON(ajaxUrl, { oper: "GetOnlineUsers" }, function(data) {
        if (data && data.msg == "suc") {
            aa = '';
            for (var i = 0; i < data.users.length; i++) {
                aa = aa + "<li class='online'>" + data.users[i].username + "</li>";
            }
            if (aa.length > 0) {
                $("li.online").remove();
                $(aa).insertAfter('#lo')
            }
        }
    });
}
function GetGoodsInfoByGoodsId(id, sellerid) {
    try {
        AcceptGetGoodsDetails(id);
        GetGoodsFLow(id);

        GetSellerInfo(sellerid);
        GetGoodsSmsInfo(id);
    } catch (err) {
        unloadboy();
        alert(err);
    }
}
function AcceptGetGoodsDetails(goodsid) {
        loadbody();
        $.getJSON(ajaxUrl, { oper: "GetGoodsInfoById", id: goodsid, random: Math.random() },
        function(data) {

            $("#goodsPrice").html("0.00");
            $("#goodsbuycount").html("0");
            $("#goodspackfee").html("0.00");
            $("#goodsshowpic").removeAttr("href");
            $("#goodsshowurl").removeAttr("href");
            $("#goodsimg").removeAttr("src");
            $("#goodsmemo").val("");
            $("#goodsfinancialmemo").val("");
            $("#buyermemo").val("");
            $("#hiddenGoodsId").val("0");
            $("#hiddenGoodsPackFee").val("0");
            $("#hiddenGoodsCount").val("0");
            $("#hiddenGoodsPrice").val("0");
            $("#hiddenGoodsState").val("0");
            $("#goodssnappic").removeAttr("href");
            if ($.browser.msie) {
                $("#GoodsRealTotalPrice").unbind("propertychange", CalculateGoodsPrice);
                $("#GoodsRealPackFee").unbind("propertychange", CalculateGoodsPrice);
            }
            else {
                $("#GoodsRealTotalPrice").unbind("blur", CalculateGoodsPrice);
                $("#GoodsRealPackFee").unbind("blur", CalculateGoodsPrice);
            }
            if (data && data.msg == "suc") {
                if (data.goodsInfo.length > 0) {
                    var goods = data.goodsInfo[0];
                    $("#goodsPrice").html(goods.goodsprice);
                    $("#goodsbuycount").html(goods.goodscount);
                    $("#goodspackfee").html(goods.goodspackfee);
                    $("#goodsshowpic").attr("href", goods.goodspicurl);
                    $("#goodsimg").attr("src",  goods.goodspicurl);
                    $("#goodsshowurl").attr("href", goods.goodsurl);
                    $("#goodsmemo").val(goods.goodsmemo);
                    $("#goodsfinancialmemo").val(goods.goodsfinancialmemo);
                    $("#buyermemo").val(goods.goodsbuyermemo);
                    $("#hiddenGoodsId").val(goods.goodsid);
                    $("#GoodsRealTotalPrice").val(goods.realprice);
                    $("#GoodsRealPackFee").val(goods.realpackfee);
                    $("#GoodsBarGin").val(goods.goodsbargain);
                    $("#goodsTypeSelect").attr("value", goods.goodstypefid);
                    $("#hiddenGoodsPackFee").val(goods.goodspackfee);
                    $("#hiddenGoodsCount").val(goods.goodscount);
                    $("#hiddenGoodsPrice").val(goods.goodsprice);
                    $("#hiddenGoodsState").val(goods.goodtypeid);
                    $("#goodssnappic").attr("href", goods.goodshtmlpath);
                    if ($.browser.msie) {
                        $("#GoodsRealTotalPrice").bind("propertychange", CalculateGoodsPrice);
                        $("#GoodsRealPackFee").bind("propertychange", CalculateGoodsPrice);
                    }
                    else {
                        $("#GoodsRealTotalPrice").bind("blur", CalculateGoodsPrice);
                        $("#GoodsRealPackFee").bind("blur", CalculateGoodsPrice);
                    }
                    CalculateGoodsPrice();


                }


            }
            unloadboy();

        });
}
     function GetSellerInfo(sellerId) {
         loadbody();
         $.getJSON(ajaxUrl, { oper: "GetGoodsBuyerSellerInfo", sellerid: sellerid, random: Math.random() }, function(data) {
             $("#returntype").html("");
             $("#returnlevel").html("");
             $("#returnmemo").val("");
             if (data && data.msg == "suc") {
                 $("#returntype").html(data.sellerretruntype);
                 $("#returnlevel").html(data.sellerretrunlevel);
                 $("#returnmemo").val(data.sellermemo);
             }
             unloadboy();

         });
     }
    function GetGoodsSmsInfo(goodsId) {
        $.getJSON(ajaxUrl, { oper: "GetGoodsBuyerSmsInfo", id: goodsId, random: Math.random() }, function(data) {
            loadbody();
            $("#smsInfo").html("");
            if (data && data.msg == "suc") {
                if (data.smsinfo.length > 0) {
                    var vhtml = '';
                    for (var i = 0; i < data.smsinfo.length; i++) {
                        vhtml = vhtml + "<span>" + data.smsinfo[i].smssendtime + "</span><br /><label>" + data.smsinfo[i].smscontent + "</label><br />";
                    }
                    $("#smsInfo").html(vhtml);
                }
            }
            unloadboy();

        });
    }
    function GetGoodsFLow(goodsid) {
        $.getJSON(ajaxUrl, { oper: "GetGoodsFlowByFlow", id: goodsid, random: Math.random() }, function(data) {
            loadbody();
            $("#goodsFLowList").find("tr:gt(0)").remove();
            if (data && data.msg == "suc") {


                if (data.goodsFlow.length > 0) {
                    var trs = '';
                    for (var goodsFlowindex = 0; goodsFlowindex < data.goodsFlow.length; goodsFlowindex++) {
                        trs = trs + "<tr><td>" + data.goodsFlow[goodsFlowindex].flowcreatetime + "</td><td>" + data.goodsFlow[goodsFlowindex].username
                        + "</td><td>" + data.goodsFlow[goodsFlowindex].flowtypename + "</td><td>" + data.goodsFlow[goodsFlowindex].flowtitle + "</td>";
                    }

                    $("#goodsFLowList").append(trs);
                  
                    FixTable("goodsFLowList", 0, parseInt(flowWidth), 200);
                }
            }
            unloadboy();


        });
     }

function OnSelect(obj) {
    var parent = obj.parent();
    parent.children("tr").each(function() {
        $(this).removeClass('highlight');
    });
    obj.addClass('highlight');

}
var flowWidth = 0;
 function OnAcceptSelect(obj) {
    var parent = obj.parent();
    parent.children("tr").each(function() {
    $(this).removeClass('selectrow');
    });
    if (flowWidth == 0)
        flowWidth = $("#goodsFLowList").outerWidth();
  goodsid = obj.find("td .goodsid").val();
    sellerid = obj.find("td .sellerId").val();
    obj.addClass('selectrow');
    if ($("#hiddenGoodsId").val() == goodsid)
        return;
  
    if (goodsid && goodsid > 0) {
        GetGoodsInfoByGoodsId(goodsid,sellerid);
     }
 }
 function OnAcceptIniSelect(obj) {
    
     var parent = obj.parent();
     
     parent.children("tr").each(function() {
         $(this).removeClass('selectrow');
     });
     if (flowWidth == 0)
         flowWidth = $("#goodsFLowList").outerWidth();
     goodsid = obj.find("td .goodsid").val();
     sellerid = obj.find("td .sellerId").val();
     obj.addClass('selectrow');
     if ($("#hiddenGoodsId").val() == goodsid)
         return;

     if (goodsid && goodsid > 0) {
         GetGoodsInfoByGoodsId(goodsid, sellerid);
     }
 }
 var yloading = null;
 function loadbody() {

     var height = $(document).scrollTop();
     var loading = '<div id="overlay" style="position:absolute;top:' + height + 'px;left:0;z-index:9999;overflow:hidden;sposition:fixed; width:100%; height:100%;background:#333;filter: Alpha(opacity=50); -moz-opacity:.5;opacity:0.5;"><table width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td align="center"><img src="/res/img/loadingAnimation.gif">正在加载……</td></tr></table></div>';

     var s = $("#overlay").html();
     if (s == null) {
         yloading = $(loading);
         yloading.appendTo('body');
     } else {
         yloading = $("#overlay");
     }

     if (yloading) {
         yloading.show();
     }
 }
function unloadboy() {
    var s = $("#overlay").html();
    if (s != null) {
        yloading = $("#overlay");
        yloading.remove();

    }
}

function UpdateRights(user) {
    var user = user;
    rights=document.forms[0].rights
    txt=""
    for (i=0;i<rights.length;++ i)
    {
        if (rights[i].checked)
        {
            txt=txt + rights[i].value + "^"
        }
    }
    var url = ajaxUrl;
    $.ajax({
        type: 'POST',
        url: url,
        data: { oper: 'UpdateRights', u: user, r: txt },
        success: function(request) {
            if (request == 'invalidOrNull') {
                alert('系统错误。');
                return;
            }
            if (request == '1') {
                alert('设置成功！');
                return;
            }
        }
    });
}
function CalculateGoodsPrice() {
    var realPayGoodsmoney = $("#GoodsRealTotalPrice").val();
    var realPayPackFee =$("#GoodsRealPackFee").val();
    var goodsprice = $("#hiddenGoodsPrice").val();
    var goodsCount = $("#hiddenGoodsCount").val();
    var goodspackFee =$("#hiddenGoodsPackFee").val();
    var goodsId = $("#hiddenGoodsId").val();
  
    $.ajax({
        type: 'POST',
        url: ajaxUrl,
        beforeSend: loadbody(),
        data: {
            oper: 'VeriGoodsPrice',
            goodsid: goodsId,
            goodspayprice: realPayGoodsmoney,
            goodspaypackfee: realPayPackFee,
            goodsprice: goodsprice,
            goodscount: goodsCount,
            goodspackfee: goodspackFee
        },
        dataType: "json",
        success: function(data, textStatus) {
            if (data && data.msg == 'suc') {
                $("#realBargin").html(data.goodsreturnfee);
                $("#needPayPrice").html(data.goodsneedpayprice);
            } else
                if (data && data.msg != 'err') {
                alert(data.msg);
            }
            
        },
        error:unloadboy()

    });


}
function uploadGoodsImg() {
    var goodsId = $("#hiddenGoodsId").val();
    loadbody();
    $("#goodsimg").removeAttr("src");
    $("#goodsshowpic").removeAttr("href");
    $("#goodssnappic").removeAttr("href");
    $.getJSON(ajaxUrl, { oper: "UploadeImg", goodsid: goodsId, mathcount: Math.random() }, function(data) {
        if (data && data.msg == "suc") {
            $("#goodsimg").attr("src",  data.goodspicurl);
            $("#goodsshowpic").attr("href",  data.goodspicurl);
            $("#goodssnappic").attr("href", data.goodshtmlurl);
        }
        unloadboy();

    })//由nina编写
}
function updateBuyerGoodsInfo() {

    var realPayGoodsmoney = $("#GoodsRealTotalPrice").val();
    if (realPayGoodsmoney == '' || !parseFloat(realPayGoodsmoney) || parseFloat(realPayGoodsmoney) <= 0) {
        alert("商品价格输入有误,请重新输入");
        return;
    }
    var realPayPackFee = $("#GoodsRealPackFee").val();
    if (realPayPackFee == '' || parseFloat(realPayPackFee) < 0) {
        alert("运费输入有误,请重新输入");
        return;
    }
    var goodsprice = $("#hiddenGoodsPrice").val();
    var goodsCount = $("#hiddenGoodsCount").val();
    var goodspackFee = $("#hiddenGoodsPackFee").val();
    var goodsId = $("#hiddenGoodsId").val();
    var goodsState = $("#hiddenGoodsState").val();
    var goodstype = $("#goodsTypeSelect").val();
    if (goodstype == null || goodstype == '' || parseInt(goodstype) < 0) {
        alert("请选择商品类型");
        return;
    }
    var goodsbuyermemo = $("#buyermemo").val();
    var goodsmoneymemo = $("#goodsfinancialmemo").val();
    var goodsbargin = $("#GoodsBarGin").val();
    if (goodsbargin == '' || parseFloat(goodsbargin) < 0) {
        alert("议价金额输入有误,请重新输入");
        return;
    }
    $.ajax({
        type: "POST",
        url: ajaxUrl,

        beforeSend: loadbody(),
        error: function() { GetGoodsFLow(goodsId); unloadboy() },
        data: {
            oper: "UpdateGoodsInfoWaitToSubmit",
            goodsid: goodsId,
            goodspayprice: realPayGoodsmoney,
            goodspaypackfee: realPayPackFee,
            goodsprice: goodsprice,
            goodscount: goodsCount,
            goodspackfee: goodspackFee,
            goodsbargin: goodsbargin,
            goodsState: goodsState,
            goodstype: goodsState,
            goodsbuyermemo: goodsbuyermemo,
            goodsmoneymemo: goodsmoneymemo
        },
        dataType: 'JSON',
        success: function(data, textStatus) {
            try {
                if (data && data.msg == 'suc') {
                    $("table tr td ").children("#" + goodsId).each(function() { $(this).parent().parent().find(".flowtypename").html(data.goodsToStateStr) });
                    $("table tr td ").children("#" + goodsId).each(function() { $(this).parent().parent().find(".flowtypeid").val(data.goodsToState) });
                    $("#hiddenGoodsState").val(data.goodsToState);
                    $("#realBargin").html(data.goodsreturnfee);
                    $("#needPayPrice").html(data.goodsneedpayprice);
                    alert("提交成功");
                }
                else if (data.msg == 'err') {

                }
                GetGoodsFLow(goodsId); unloadboy();
            } catch (err) {
                GetGoodsFLow(goodsId); unloadboy(); alert(err);
            }
        }
    });
}

//审核通过
function CheckInvoiceOrder(orderId) {
    $.getJSON(ajaxUrl + "?rnd=" + Math.round(Math.random() * 10), { oper: "CheckInvoiceOrder", orderId: orderId }, function(data) {
        if (data && data.msg == "suc") {
            alert("成功");
            location.href = "/invoice/InvoiceList.aspx";
        }
        else {
            alert("失败");
        }
    });
}
//审核不通过
function NoCheckInvoiceOrder(orderId) {
    var meno = $('#reason_' + orderId).val();
    if (meno == '') {
        alert("请输入审核不通过原因！");
        return;
    }
    $.getJSON(ajaxUrl + "?rnd=" + Math.round(Math.random() * 10), { oper: "NoCheckInvoiceOrder", orderId: orderId, meno: meno }, function(data) {
        if (data && data.msg == "suc") {
            alert("成功");
            location.href = "/invoice/InvoiceList.aspx";
        }
        else {
            alert("失败");
        }
    });
}
//配送
function DeliverInvoiceOrder(orderId) {
    var Fedex = $('#fedex_' + orderId).val();
    var FedexComPany = $('#comp_' + orderId).val();
    if (FedexComPany == '') {
        alert("请输入快递公司！");
        return;
    }
    if (Fedex == '') {
        alert("请输入快递单号！");
        return;
    }

    $.getJSON(ajaxUrl + "?rnd=" + Math.round(Math.random() * 10), { oper: "DeliverInvoiceOrder", orderId: orderId, Fedex: Fedex, FedexComPany: FedexComPany }, function(data) {
        if (data && data.msg == "suc") {
            alert("成功");
            location.href = "/invoice/InvoiceList.aspx";
        }
        else {
            alert("失败");
        }
    });
}
//验证用户名
function checkCustName(custName) {
    $.getJSON(ajaxUrl + "?rnd=" + Math.round(Math.random() * 10), { oper: "checkCustName", custName: custName }, function(data) {
        if (data && data.msg == "suc") {
            document.getElementById("price").innerHTML = "&nbsp;&nbsp;账户余额：￥" + data.price;
        }
        else {
            document.getElementById("price").innerHTML = "";
            alert("该经销商不存在，请重新输入");
        }
    });
}
function GetLoginLogHistory(custId){
    $.getJSON(ajaxUrl + "?rnd=" + Math.round(Math.random() * 10), { oper: "GetLoginLog", custId: custId }, function(g) {
        if (g && g.msg == "suc") {
            var j = g.data;
            var content;
            $.each(j, function(index, item) {
                content += "<tr><td>" + item.time + "</td><td>" + item.ip + "</td></tr>";
            });
        }
        if ($.trim(content) == "") {
            content = "<tr><td colspan=\"2\">暂无相关信息</td></tr>";
        }
        $(".infowrap").show();
        $(".login_log_history").html(content.replace(new RegExp(/(T)/g), '  '));
        window.location.hash = "#login_log";
    });
}